/*
 * Copyright (c) 2010 - 2011, Brookhaven National Laboratory
 * All rights reserved.
 * The software in this package is published under the terms
 * of the BSD license a copy of which has been included with
 * this distribution in the license.txt file.
 */


package org.oxtypes.impl;

import java.math.BigDecimal;

import org.omg.dds.type.dynamic.DynamicType;

import org.oxtypes.DynamicData;
import org.oxtypes.DynamicTypeFactory;

/**
 *
 */
public class SequenceImpl {

    /** Sequence of floats */
    public static class DoubleSequence extends AbstractDynamicData {

        private DynamicType type;
        private double[] values;

        public DoubleSequence(int bound){
           DynamicTypeFactory dtf = DynamicTypeFactory.getInstance();
           type = dtf.createSequenceType(DynamicTypeManagerImpl.float64Type,
                   bound);
        }

        public int getLength(){
            if(values == null) return 0;
            return values.length;
        }

        public DynamicType getType(){
            return  type;
        }

        public DynamicData setInt16Value(int id, short value){
            this.values[id] = value;
            return this;
        }

        public DynamicData setInt32Value(int id, int value){
            this.values[id] = value;
            return this;
        }

        public DynamicData setFloat32Value(int id, float value){
            this.values[id] = value;
            return this;
        }

        public DynamicData setFloat64Value(int id, double value){
            this.values[id] = value;
            return this;
        }

        public double getFloat64Value(int id){
            return this.values[id];
        }

        public BigDecimal getBigDecimalValue(int id){
            return new BigDecimal(this.values[id]);
        }

        public int getFloat64Values(double[] value, int offset, int length, int id){
            System.arraycopy(this.values, 0, this.values, offset, length);
            return 0;
        }

        public DynamicData setFloat64Values(int id, double[] values, int offset, int length){
            if(this.values == null || this.values.length != length) {
                this.values = new double[length];
            }
            System.arraycopy(values, offset, this.values, 0, length);
            return this;
        }

        /** Unsupported */
        public DynamicData setFloat64Values(int id, double... value){
            throw new java.lang.UnsupportedOperationException();
        }
    }

}
